package com.jack.netty.udp.server;

import com.jack.netty.log.LoggerManager;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;

/**
 * Created by jack on 15/12/11.
 */
public class UdpServer {

    private Bootstrap bootstrap;
    private EventLoopGroup eventLoopGroup;
    private int port = 9999;

    private UdpServerHandler udpServerHandler;

    public UdpServer(){

    }


    public void start(){
        bootstrap = new Bootstrap();
        eventLoopGroup = new NioEventLoopGroup();
        bootstrap.group(eventLoopGroup);
        bootstrap.channel(NioDatagramChannel.class);
        bootstrap.option(ChannelOption.SO_BROADCAST,true);
        udpServerHandler = new UdpServerHandler();
        bootstrap.handler(udpServerHandler);
        try {
            bootstrap.bind(port).sync().channel().closeFuture().wait();
        }catch (Exception e){
            LoggerManager.getInstance().getiLogger().error(getClass(),"启动UDP错误:"+e.getMessage());
        }

    }

    public void stop(){

    }

    public void restart(){

    }



}
